import storage from './storage'
const SESSION_KEY_USER = 'userInfo'
const MENU_KEY = 'menuInfo'
const config = [
  {
    name: SESSION_KEY_USER,
    type: 'object'
  },
  {
    name: MENU_KEY,
    type: 'object'
  }
]
const sessionstorage = new storage('sessionStorage', window.sessionStorage, config)

/* 设置用户登录后token session 信息*/
export function setUserInfo(userInfo) {
  sessionstorage.set(SESSION_KEY_USER, userInfo)
}

export function getUserInfo() {
  return sessionstorage.get(SESSION_KEY_USER)
}

export function clearUserInfo() {
  sessionstorage.remove(SESSION_KEY_USER)
}

export function isUserLogin() {
  let user = getUserInfo()
  if (user === null || user === undefined || JSON.stringify(user) === '{}' ) return false
  return true
}



export function setMenuInfo(obj) {
  sessionstorage.set(MENU_KEY, obj)
}

export function getMenuInfo() {
  return sessionstorage.get(MENU_KEY)
}

export function clearMenuInfo() {
  sessionstorage.remove(MENU_KEY)
}
